

/************* include files ************************/
#include "stm8s.h"
#include "..\include\Cpu_Pin_Configuration.h"
#include "..\include\Global_Decleration.h"
#include "stm8s_flash.h"

#include "..\include\Global_Functions.h"
#include "..\include\Core_Initialize.h"
#include "..\include\Lcd_Driver.h"
#include "..\include\Menu_Control.h"

uint16_t rpmValue;
uint8_t  timeValue ;


void main(void)
{
	uint16_t tempValue = 0;
	uint8_t i;
	uint8_t cursorPosition = CURSOR_POSITION_NONE;
	uint8_t menuOpen = FALSE;
	uint8_t refreshScreen = FALSE;
	
	rpmValue = 3050;
	timeValue = 4;


	CORE_initalizeAllGpio();
	LCD_init();

/*************  starting anumation ******************/
	LCD_gotoLcd_xy(1,4);
	LCD_printString("STARTING");	
	LCD_gotoLcd_xy(2,1);
	
	for (i = 0; i < 16; i++) {
		LCD_printchar('.');
		delay_ms(100);
	}
/***********************************************/	
	
	LCD_clearDisplay();
	LCD_printNumber (rpmValue);
	LCD_gotoLcd_xy(2,1);
	LCD_printNumber ((uint16_t)timeValue);
	
	//showScreen();

	while(1) {

		if(IS_MENU_BUTTON_PRESSED) {
			while (IS_MENU_BUTTON_PRESSED)
				;
			cursorPosition = CURSOR_POSITION_RPM;

			if (menuOpen) {
				showScreen();
				menuOpen = FALSE;
				refreshScreen = FALSE;				
			}
			else {
				menuOpen = TRUE;
				refreshScreen = TRUE;
			}

		}
		else if (menuOpen) {
			if (IS_UP_BUTTON_PRESSED) {	
				while (IS_UP_BUTTON_PRESSED)
					;
				switch(cursorPosition) {
					case CURSOR_POSITION_RPM:						
						rpmValue++;
						
						if (MAX_RPM < rpmValue)
							rpmValue--;
						
						refreshScreen = TRUE;
						break;
			
					case CURSOR_POSITION_TIME:
						timeValue++;
						
						if (MAX_TIME < timeValue)
							timeValue--;
						
						refreshScreen = TRUE;
						break;
						
					default:
						break;
				}
			}
			else if (IS_DOWN_BUTTON_PRESSED) {	
				while (IS_DOWN_BUTTON_PRESSED)
					;
				switch(cursorPosition) {
					case CURSOR_POSITION_RPM:
						rpmValue--;
						
						if (MIN_RPM > rpmValue)
							rpmValue++;						
						
						refreshScreen = TRUE;
						break;

					case CURSOR_POSITION_TIME:
						timeValue--;
						
						if (MIN_RPM > timeValue)
							timeValue++;	
						
						refreshScreen = TRUE;
						break;
						
					default:
						break;
				}
			}
			else if (IS_CURSOR_BUTTON_PRESSED) {
				while (IS_CURSOR_BUTTON_PRESSED)
					;								
				cursorPosition++;
				
				if (CURSOR_POSITION_MAXNUMBER <= cursorPosition)
					cursorPosition = CURSOR_POSITION_RPM;					

				refreshScreen = TRUE;

			}
			if (refreshScreen){
				showSettingScreen(cursorPosition);
				refreshScreen = FALSE;
			}


		}




		
}




}
void assert_failed(uint8_t* file, uint32_t line)
{ 
	while (1);
}








































